<template>
  <div class="find statusBar">
    <van-nav-bar title="发现" />
    <div class="box">
      <div class="booklist">
        <div class="item" v-for="(item, index) in booklistsData" :key="index" @click="goToBooklists(item._id)">
          <img class="img" :src="item.cover" alt="">
          <!-- <img :src="item.covers[0]" alt="">
          <img :src="item.covers[1]" alt=""> -->
          <div>
            <div class="title one-text">{{item.title}}</div>
            <div class="desc">{{item.desc}}</div>
            <div class="other">
              <div class="author">{{item.author}}</div>
              <div class="readCount">{{item.readCount}}人阅读</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'Find',

    data() {
      return {
        // 书单数据
        booklistsData: []
      }
    },

    created() {
      this.getBooklists();
    },

    methods: {
      // 获取书单数据
      getBooklists() {
        this.axios.get('booklists')
        .then(res => {
          // console.log('getBooklists res', res);
          if(res.status === 200) {
            res.data.bookLists.forEach(v => {
              v.cover = decodeURIComponent(v.cover.split('/')[2]);
              for(let i = 0; i < v.covers.length; i++) {
                v.covers[i] = decodeURIComponent(v.covers[i].split('/')[2])
              }
            })
            this.booklistsData = res.data.bookLists;
            // console.log(this.booklistsData);
          }
        }).catch(err => {
          console.log('err', err);
        })
      },

      // 跳转到书单详情页
      goToBooklists(bookId) {
        this.$router.push({name: 'BooklistDetails', query: {bookId}})
      },
    }
  }
</script>

<style lang="less" scoped>
::v-deep .van-nav-bar__title {
  color: #00bb86;
  font-size: 16px;
}
.box {
  position: fixed;
  top: 46px + 28px;
  bottom: 50px;
  left: 0;
  right: 0;
  overflow-y: auto;
}
.booklist {
  padding: 0 20px;
  .item {
    display: flex;
    align-items: center;
    padding: 20px 0;
    border-bottom: 1px solid #eee;
    &:last-child {
      border-bottom: 0;
    }
    .img {
      margin-right: 15px;
      width: 60px;
      height: 80px;
      border-radius: 2px;
      box-shadow: 1px 1px 2px #aaa;
    }
    .title {
      max-width: 260px;
      color: #333;
      font-size: 14px;
      font-weight: bold;
    }
    .desc {
      margin: 5px 0;
      max-width: 260px;
      color: #999;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      // height: 250px;
      text-overflow: ellipsis;
      overflow: hidden;
    }
    .other {
      display: flex;
      align-items: center;
      color: #ccc;
    }
    .readCount {
      flex: 1;
      margin-left: 10px;
    }
  }
}
</style>